package chances.webui.taglibs;

import java.util.Collection;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;

import chances.webui.helper.LookupHelper;

@SuppressWarnings("serial")
public class LookuperTag extends TagSupport {

	Logger logger = LoggerFactory.getLogger(LookuperTag.class);
	private Object source;
	private String key;
	private String value;
	private String scope;
	private String var;

	@Override
	public int doEndTag() throws JspException {
		Assert.notNull(this.source);

		if (source instanceof Collection) {
			pageContext.setAttribute(this.var, LookupHelper.build((Collection<?>) source, key, value));
		}
		return super.doEndTag();
	}

	public Object getSource() {
		return source;
	}

	public String getKey() {
		return key;
	}

	public String getValue() {
		return value;
	}

	public void setSource(Object source) {
		this.source = source;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getScope() {
		return scope;
	}

	public String getVar() {
		return var;
	}

	public void setScope(String scope) {
		this.scope = scope;
	}

	public void setVar(String var) {
		this.var = var;
	}

}
